#include "test_modem.h"
#include "cm_uart.h"
#include "cm_demo_uart.h"
#include "cm_mem.h"
#include "stdlib.h"
#include "string.h"



void cm_test_modem_operation(unsigned char*cmd[],int len)
{
    if(0 == strcmp("CGMM",cmd[2]))
    {
        char cgmm[65] = {0};
        int32_t ret = cm_modem_get_cgmm(cgmm);
        cm_demo_printf("cgmm:%s\n",cgmm);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret,cm_modem_get_cgmm);
    }
    else if(0 == strcmp("CGMI",cmd[2]))
    {
        char cgmi[65] = {0};
        int32_t ret = cm_modem_get_cgmi(cgmi);
        cm_demo_printf("cgmi:%s\n",cgmi);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret,cm_modem_get_cgmi);
    }
    else if(0 == strcmp("COPS",cmd[2]))
    {
        cm_cops_info_t *cops = (cm_cops_info_t*)cm_malloc(sizeof(cm_cops_info_t));
        int32_t ret = cm_modem_get_cops(cops);
        cm_demo_printf("act:%d, format:%d, mode:%d, oper:%s\n",cops->act,cops->format,cops->mode,cops->oper);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret,cm_modem_get_cops);
        cm_free(cops);
    }
    else if(0 == strcmp("CSQ",cmd[2]))
    {
        char rssi[9] = {0};
        char ber[9] = {0};
        int32_t ret = cm_modem_get_csq(rssi,ber);
        cm_demo_printf("rssi:%s, ber:%s\n",rssi,ber);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret,cm_modem_get_csq);
    }
    else if(0 == strcmp("RADIO_INFO",cmd[2]))
    {
        cm_radio_info_t *radio_info = (cm_radio_info_t*)cm_malloc(sizeof(cm_radio_info_t));
        int32_t ret = cm_modem_get_radio_info(radio_info);
        cm_demo_printf("last_cellid:%u, last_earfcn:%u, last_ecl:%u, last_pci:%u, last_snr:%u, rat:%u, rsrp:%u, rsrq:%u, rssi:%u, rx_time:%u, rxlev:%u, tx_power:%u, tx_time:%u\n",radio_info->last_cellid,radio_info->last_earfcn,radio_info->last_ecl,\
        radio_info->last_pci,radio_info->last_snr,radio_info->rat,radio_info->rsrp,radio_info->rsrq,radio_info->rssi,radio_info->rx_time,radio_info->rxlev,radio_info->tx_power,radio_info->tx_time);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret,cm_modem_get_radio_info);
        cm_free(radio_info);
    }else if(0 == strcmp("CELL_INFO",cmd[2]))
    {
        cm_cell_info_t cell_info[3] = {0};
        int32_t ret = cm_modem_get_cell_info(cell_info, 3);
        cm_demo_printf("cm_modem_get_cell_info ret:%d\n",ret);
        for(int i = 0;i < 3;++i)
        {
             cm_demo_printf("bandwidth:%u, earfcn:%u, earfcn_offset:%u, tac:%u, mcc:%s, mnc:%s, pci:%u, primary_cell:%u, rsrp:%u, rsrq:%u, rssi:%u, snr:%u, cid:%u\n",\
            cell_info[i].bandwidth,cell_info[i].earfcn,cell_info[i].earfcn_offset,cell_info[i].tac,cell_info[i].mcc,cell_info[i].mnc,cell_info[i].pci,cell_info[i].primary_cell,cell_info[i].rsrp,cell_info[i].rsrq,cell_info[i].rssi,cell_info[i].snr,cell_info[i].cid);
        }
        OCTEST_FUNC_EXPECT_GREATER_OR_EQUAL_INT32(0,ret,cm_modem_get_cell_info);
    }
    else if(0 == strcmp("SET_GET_CFUN",cmd[2]))
    {
        uint16_t fun = atoi(cmd[3]);
        int32_t ret = cm_modem_set_cfun(fun);
        cm_demo_printf("cm_modem_set_cfun ret:%d\n",ret);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret,cm_modem_set_cfun);
        //osDelay(1000);
        int32_t ret_2 = cm_modem_get_cfun();
        cm_demo_printf("cm_modem_get_cfun ret:%d\n",ret_2);
        OCTEST_EXPECT_EQUAL_INT32(fun,ret_2);    
    }
    else if(0 == strcmp("SET_GET_EDRX",cmd[2]))
    {
        const cm_edrx_cfg_set_t cfg = {1,4,5};
        int32_t ret = cm_modem_set_edrx_cfg(&cfg);
        cm_demo_printf("cm_modem_set_edrx_cfg ret:%d\n",ret);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret,cm_modem_set_edrx_cfg);
        //osDelay(1000);
        cm_edrx_cfg_get_t cfg_2 = {0};
        int32_t ret_2 = cm_modem_get_edrx_cfg(&cfg_2);
        cm_demo_printf("cm_modem_get_edrx_cfg ret:%d\n",ret_2);
        cm_demo_printf("act_type:%d, requested_edrx_value:%d\n",cfg_2.act_type,cfg_2.requested_edrx_value);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret_2,cm_modem_get_edrx_cfg);
    
    }
    else if(0 == strcmp("SET_GET_PSM",cmd[2]))
    {
        const cm_psm_cfg_t cfg = {1,35,34};
        int32_t ret = cm_modem_set_psm_cfg(&cfg);
        cm_demo_printf("cm_modem_set_psm_cfg ret:%d\n",ret);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret,cm_modem_set_psm_cfg);
        //osDelay(1000);
        cm_psm_cfg_t cfg_2 = {0};
        int32_t ret_2 = cm_modem_get_psm_cfg(&cfg_2);
        cm_demo_printf("cm_modem_get_psm_cfg ret:%d\n",ret_2);
        cm_demo_printf("mode:%d, tau:%d, time:%d\n",cfg_2.mode,cfg_2.requested_periodic_tau,cfg_2.requested_active_time);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret_2,cm_modem_get_psm_cfg);
    }
    else if(0 == strcmp("GET_CEREG",cmd[2]))
    {
        cm_cereg_state_t cereg = {0};
        int32_t ret = cm_modem_get_cereg_state(&cereg);
        cm_demo_printf("cm_modem_get_cereg_state ret:%d\n",ret);
        cm_demo_printf("act:%d, active_time:%d, cause_type:%d, ci:%d, lac:%d, n:%d, periodic_tau:%d, rac:%d, reject_cause:%d, state:%d, \n",cereg.act,\
        cereg.active_time,cereg.cause_type,cereg.ci,cereg.lac,cereg.n,cereg.periodic_tau,cereg.rac,cereg.reject_cause,cereg.state);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret,cm_modem_get_cereg_state);
    }else if(0 == strcmp("GET_CSCON",cmd[2]))
    {
        int32_t ret = cm_modem_get_cscon();
        cm_demo_printf("cm_modem_get_cscon ret:%d\n",ret);
        OCTEST_FUNC_EXPECT_GREATER_OR_EQUAL_INT32(0,ret,cm_modem_get_cscon);
    }
    else if(0 == strcmp("ACT_DEACT_PDP",cmd[2]))
    {
        uint16_t cid = atoi(cmd[3]);
        int32_t ret = cm_modem_deactivate_pdp(cid);
        cm_demo_printf("cm_modem_deactivate_pdp ret:%d\n",ret);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret,cm_modem_deactivate_pdp);
        //osDelay(1000);
        int32_t ret_2 = cm_modem_activate_pdp(cid);
        cm_demo_printf("cm_modem_activate_pdp ret:%d\n",ret_2);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret_2,cm_modem_activate_pdp);    
    }
    else if(0 == strcmp("GET_PDP_STATE",cmd[2]))
    {
        uint16_t cid = atoi(cmd[3]);
        int32_t ret = cm_modem_get_pdp_state(cid);
        cm_demo_printf("cm_modem_get_pdp_state ret:%d\n",ret);
        OCTEST_FUNC_EXPECT_GREATER_OR_EQUAL_INT32(0,ret,cm_modem_get_pdp_state);
    }
    else if(0 == strcmp("GET_CPIN",cmd[2]))
    {
        int32_t ret = cm_modem_get_cpin();
        cm_demo_printf("cm_modem_get_cpin ret:%d\n",ret);
        OCTEST_FUNC_EXPECT_GREATER_OR_EQUAL_INT32(0,ret,cm_modem_get_cpin);
    }
    else if(0 == strcmp("CGMR",cmd[2]))
    {
        char cgmr[20] = {0};
        int32_t ret = cm_modem_get_cgmr(cgmr);
        cm_demo_printf("cm_modem_get_cgmr ret:%d\n",ret);
        cm_demo_printf("cgmr:%s\n",cgmr);
        OCTEST_FUNC_EXPECT_EQUAL_INT32(0,ret,cm_modem_get_cgmr);
    }
    else{
        cm_demo_printf("param error!\n");
    }
}
